home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Can't figure this out
- Date: 19 Jan 1996 15:25 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <19JAN199615253245@erich.triumf.ca>
- References: <31000091.3778302@news.panix.com>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <31000091.3778302@news.panix.com>, dm@panix.com (Dan'l) writes...
- >I am learning C and I have not had any problems understanding most
- >concepts I have learned so far. But to date I still can't figure out
- >how the outcome of this program is 15. Somehow one of the B's ends up
- >a three and the other B a 5, or am I so off base that I can't see
- >what's really happening. Can someone please walk me through this
- >one. Thanks Dan'l
- >
- >#define A 3
- >#define B A + A
-
- This makes B = "3 + 3", not 6 - #defines just do text substitution, not
- arithmetic.
-
- >#define C B * B
-
- Now C = 3 + 3 * 3 + 3. The multiplication will be done first, so you get
- 3 + 9 + 3 = 15
-
- If you _really_ must do something like this, enclose the expressions in
- parenthesis, like so:
- #define A 3
- #define B ((A) + (A))
- #define C ((B) * (B))
-
- I think I have enough parentheses there to ensure things are evaluated in the
- right order... :-)
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-